const express = require('express')
const app = express();





//解决跨域
app.use('*',function(req,res,next){
    res.header("X-Powered-By",' 3.2.1')
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Content-Type", "application/json;charset=utf-8");
    res.header("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");

    res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
    next()
});

app.get('/test',function (req,res){
    res.send({code:200,data:[
            {
                path: 'test',
                name: 'test',
                component: 'Layout',
                meta: { title: '测试页面', icon: 'ios-pin' },
                children: [
                    {
                        path: 'test',
                        name: 'test',
                        meta: { title: '测试页面', icon: 'ios-pin' },
                    },
                ]
            },
            {
                path: 'test2',
                name: 'test2',
                meta: { title: '测试目录', icon: 'ios-pin' },
                component: 'Layout',
                children:[
                    {
                        path: 'test3',
                        name: 'test3',
                        meta: { title: '测试3', icon: 'ios-pin' },
                    },
                    {
                        path: 'test4',
                        name: 'test4',
                        meta: { title: '测试4', icon: 'ios-pin' },
                    }
                ]
            }
        ]})
})

app.post('/test2',function (req,res){
    setTimeout(()=>{
        res.send({code:200,})
    },3000)

})

app.listen(3000,function (err) {
    if(err){
        console.log(err)
    }
    console.log("启动成功 port 3000")
})
